<template>
    <div class="main">
        <van-checkbox-group v-model="checked" v-if="1">
            <Foodlistitem :show="true" :list="store.state.list" :shou="true">
            </Foodlistitem>
        </van-checkbox-group>
        <span class="span">总价格：￥{{ price }}</span>
        <span class="span">使用优惠券后价格为：￥{{ lastprice }}</span>
    </div>
</template>

<script>
import { reactive, toRefs, computed } from 'vue';
import { useStore } from 'vuex';
import Foodlistitem from '../../components/store/Foodlistitem.vue'

export default {
    components: {
        Foodlistitem
    },

    setup() {
        const store = useStore()
        const data = reactive({
            cartdetaillist: [],
            checked: [],
            list: [],
            price: 0,
            lastprice:0
        })
        store.state.cartlist.forEach((itema) => {
            itema.children.forEach((item) => {
                if (item.num > 0) {
                    data.list.push(item)
                    store.commit('addlist', data.list)
                }
            })
        });
        const init = () => {
            // console.log(1);
            store.state.list.map((item) => {
                data.checked.push(item.id)
            })
        }
        init()
        data.price = computed(() => {
            let num = 0
            store.state.list.map((item) => {
                num += item.price * item.num
            })
            return num
        })
        data.lastprice=computed(()=>{
return data.price*0.8
        })

        // price()
        return { ...toRefs(data), store }
    }
}
</script>

<style lang="scss" scoped>
.span {
    margin-bottom: 10px;
    text-align: center;
    display: block;
}

.main {
    background-color: #fff;
    padding: 5px 20px;
    margin: 5px 20px;

}

.item {
    margin-top: 10px;
    display: flex;

    img {
        width: 60px;
        height: 60px;
        border-radius: 10px;
        margin-right: 20px;
    }

    .txt {
        width: 80px;
        font-size: 14px;

        .stepper {
            margin-top: 5px;

        }

        :deep .van-stepper__input,
        :deep .van-stepper__minus,
        :deep .van-stepper__plus {
            width: 24px;
            height: 24px;
        }
    }

    .price {
        margin-left: 10px;
        font-size: 14px;
        display: flex;
        flex-direction: column;
        align-items: center;

        :deep .van-icon-add-o:before {
            margin-top: 10px;
        }
    }
}

:deep .van-sidebar-item--select:before {
    background-color: #ffc400;
    width: 3px;
    // top: 9px;
    // left: -2px;
    height: 10px;
    // transform: translateX(20px);
    transition-duration: 0.3s;
    // position: relative;
}

:deep .van-sidebar-item__text {
    font-size: 10px;

}

:deep .van-tree-select__nav {
    padding-left: 35px;
    background: #fff;
}

:deep .van-tree-select {
    margin-top: 0px;
    height: 380px !important;
}

:deep .van-sidebar-item {
    margin-bottom: 7px;
    background-color: #fff;
    overflow: visible;
}

:deep .van-sidebar-item__text {
    font-size: 14px;
}
</style>